package com.atguigu.controller;

import com.atguigu.common.result.R;
import com.atguigu.common.utils.JwtHelper;
import com.atguigu.service.OrderService;
import com.atguigu.yygh.enums.OrderStatusEnum;
import com.atguigu.yygh.model.order.OrderInfo;
import com.atguigu.yygh.vo.order.OrderCountQueryVo;
import com.atguigu.yygh.vo.order.OrderQueryVo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/api/order/orderInfo")
public class OrderApiController {
    @Autowired
    private OrderService orderService ;
    //平台排班id
    @PostMapping("auth/submitOrder/{scheduleId}/{patientId}")
    public R sumbitOrder(@PathVariable String scheduleId, @PathVariable Long patientId){
        Long orderId = orderService.saveOrder(scheduleId, patientId);
        return  R.ok().data("orderId",orderId);
    }
    //页面详情id
    @GetMapping("auth/getOrders/{orderId}")
    public R getOrders(@PathVariable Long orderId) {
        OrderInfo orderInfo = orderService.getOrderInfo(orderId);
        return R.ok().data("orderInfo",orderInfo);
    }

    /**
     * 取消预约
     * @param orderId
     * @return
     */
    @GetMapping("auth/cancelOrder/{orderId}")
    public R cancelOrder(@PathVariable("orderId") Long orderId){
        Boolean flag= orderService.cancelOrder(orderId);
        return  R.ok().data("flag",flag);
    }

    /**
     *  查看订单列表
     * @param page
     * @param limit
     * @param orderQueryVo
     * @param request
     * @return
     */
    @GetMapping("auth/{page}/{limit}")
    public  R  List(@PathVariable Long page, @PathVariable Long limit, OrderQueryVo orderQueryVo , HttpServletRequest  request){
        Long userId = JwtHelper.getUserId(request.getHeader("token"));
        orderQueryVo.setUserId(userId);
        Page<OrderInfo> orderInfoPage =new Page<>(page,limit);
        orderService.selectPage(orderInfoPage,orderQueryVo);
        return  R.ok().data("pageModel",orderInfoPage);
    }

    /**
     * 订单列表状态
     * @return
     */
    @GetMapping("auth/getStatusList")
    public R getStatusList() {
        return R.ok().data("statusList", OrderStatusEnum.getStatusList());
    }
    /**
     * 列表统计
     * @param orderCountQueryVo
     * @return
     */
    @PostMapping("inner/getCountMap")
    public Map<String, Object> getCountMap(@RequestBody OrderCountQueryVo orderCountQueryVo) {
        return orderService.getCountMap(orderCountQueryVo);
    }



}
